package com.yanglei.demo.framework.core.util;

import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;

/**
 * 客户端工具类
 */
public class ServletUtils {

    /**
     * 返回JSON字符串
     * @param response
     * @param object
     */
    @SuppressWarnings("deprecation") // 必须使用 APPLICATION_JSON_UTF8_VALUE，否则会乱码,@SuppressWarnings 忽略警告
    public static void writeJSON(HttpServletResponse response,Object object){
        String content = JSONUtil.toJsonStr(object);
        ServletUtil.write(response,content, MediaType.APPLICATION_JSON_UTF8_VALUE);
    }
}
